package com.po;

import com.utils.JDBCUnits;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 获取信封的基本信息
 */
public class Envelope {
    //信封的名字
    private String name;
    //信封的状态，是公开的还是封闭的
    private String state;
    //信封创建的时间
    private String create_time;
    //信封的编号
    private int envelope_id;
    //信封拥有者的名字
    private String user_name;
    //信封拥有者的性别
    private String user_sex;
    //获取整个信封获取赞的总数
    private int total_like;

    public int getTotal_like() {
        return total_like;
    }

    public void setTotal_like(int total_like) {
        this.total_like = total_like;
    }

    public String getUser_sex() {
        return user_sex;
    }

    public void setUser_sex(String user_sex) {
        this.user_sex = user_sex;
    }

    public String getUser_name() {
        return user_name;
    }

    public void setUser_name(String user_name) {
        this.user_name = user_name;
    }

    public int getEnvelope_id() {
        return envelope_id;
    }

    public void setEnvelope_id(int envelope_id) {
        this.envelope_id = envelope_id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public void setCreate_time(Date date) {
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        this.create_time = format.format(date);
    }

    public String getCreate_time() {
        return create_time;
    }


    public static int setTotalLike(int envelope_id){
        int total = 0;
        Connection c = null;
        PreparedStatement ps = null;
        ResultSet rs = null;

        try {
            c = JDBCUnits.getConnectino();
            String sql = "select getPraise from note where envelope_id = ?";
            ps = c.prepareStatement(sql);
            ps.setInt(1,envelope_id);
            rs = ps.executeQuery();
            while(rs.next()){
                total+=rs.getInt("getPraise");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            JDBCUnits.close(c,ps,rs);
        }

        return total;
    }
}
